<?php  
class ControllerCommonFooter extends Controller {
	protected $category_id = 0;
	protected $path = array();
	protected function index() {
		$this->language->load('common/footer');
		$this->load->model('catalog/category');
		$this->load->model('catalog/cat');
		$this->load->model('tool/seo_url');
		$this->data['text_powered_by'] = sprintf($this->language->get('text_powered_by'), $this->config->get('config_name'), date('Y', time()));
		$this->data['category'] = $this->getCategories(0);
		$this->data['category2'] = $this->getCategories2(0);
		$this->id = 'footer';

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/footer.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/footer.tpl';
		} else {
			$this->template = 'default/template/common/footer.tpl';
		}
		
		if ($this->config->get('google_analytics_status')) {
			$this->data['google_analytics'] = html_entity_decode($this->config->get('google_analytics_code'), ENT_QUOTES, 'UTF-8');
		} else {
			$this->data['google_analytics'] = '';
		}
		
		$this->render();
	}
	protected function getCategories($parent_id, $current_path = '') {
		$category_id = array_shift($this->path);
		
		$output = '';
		
		$results = $this->model_catalog_category->getCategories($parent_id);
		
		
		foreach ($results as $result) {	
			if (!$current_path) {
				$new_path = $result['category_id'];
			} else {
				$new_path = $current_path . '_' . $result['category_id'];
			}
			
			$output .= '<li>';
			if ($this->category_id == $result['category_id']) {
				$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&amp;path=' . $new_path)  . '"><b>' . $result['name'] . '</b></a>';
			} else {
				$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&amp;path=' . $new_path)  . '">' . $result['name'] . '</a>';
			}
        	$output .= '</li>'; 
		}
 
		
		return $output;
	}
	protected function getCategories2($parent_id, $current_path = ''){
		$cat_id = array_shift($this->path);		
		$output='';	
		$results = $this->model_catalog_cat->getCats($parent_id);
		  	
		foreach ($results as $result) {	
			if (!$current_path) {
				$new_path = $result['cat_id'];
			} else {
				$new_path = $current_path . '_' . $result['cat_id'];
			}
			
			$output .= '<li>';
			$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/cat&amp;paths=' . $new_path)  . '"><span>' . $result['name'] . '</span></a>';
			
        	$output .= '</li>'; 
		}
		return $output;
	}	
}
?>